home *** CD-ROM | disk | FTP | other *** search
- /* Source code for Authenticator by Eclectic Associates
-
- Functions for remembering (ie, archiving) a file's location to disk.
- Useful for remembering the location of a file between runs of an
- application.
-
- Revision History:
-
- 91/01/24 AIH
- - Created this file by extracting the archiving functions from the
- file library.
- */
-
- #include "ResourceTypeLib.h"
- #include "ArchiveLib.h"
- #include "FileArchiveLib.h"
-
- /* structure used to remember a file's location */
- typedef struct {
- FileDirType dir; /* directory ID */
- FileNmType name; /* name of file */
- CStr31 volnm;/* name of volume */
- } FileArchiveType;
-
- /* Archive the file to the currently open resource fork. The file
- is archived as a resource of type RSRC_FILE_TYPE and with the given
- ID. This function is most useful for remembering the location of
- a file after quiting an application. */
- OSErr FileArchiveWrite(FileType *fp, short id)
- {
- BEGIN
- FileArchiveType ar;
- HVolumeParam pb;
-
- require(FileValid(fp));
-
- /* clear archive */
- memset(&ar, sizeof(FileArchiveType), 0);
-
- /* get name of volume */
- memset(&pb, sizeof(ParamBlockRec), 0);
- pb.ioNamePtr = (StringPtr) ar.volnm;
- pb.ioVRefNum = fp->vol;
- pb.ioVolIndex = 0;
- fp->error = PBHGetVInfo(&pb, false);
- if (! fp->error) {
-
- /* fill in fields of archive */
- strcpy(ar.name, fp->cnm);
- PtoCstr(ar.volnm);
- ar.dir = fp->dir;
-
- /* write archive */
- fp->error = ArchiveWriteRsrc(RSRC_FILE_TYPE, id, &ar, sizeof(ar), FILE_VERSION);
- }
- return(fp->error);
- END
- }
-
- /* This is the inverse of FileArchiveWrite. This function reads
- in a resource of type FILE_ARCHIVE with the given ID, and
- sets up the file reference so that you can call FileOpen
- to open the archived file. The volume containing the file
- must be mounted when this function is called. */
- OSErr FileArchiveRead(FileType *fp, short id)
- {
- BEGIN
- FileArchiveType ar;
- HVolumeParam pb;
- size_t size;
- long version;
-
- /* read archive */
- size = sizeof(FileArchiveType);
- version = FILE_VERSION;
- fp->error = ArchiveReadRsrc(RSRC_FILE_TYPE, id, &ar, &size, &version);
- if (! fp->error) {
-
- /* convert volume name to volume reference number */
- memset(&pb, sizeof(ParamBlockRec), 0);
- CtoPstr(ar.volnm);
- pb.ioNamePtr = (StringPtr) ar.volnm;
- pb.ioVRefNum = 0;
- pb.ioVolIndex = -1;
- fp->error = PBHGetVInfo(&pb, false);
-
- /* set file */
- if (! fp->error)
- FileSet(fp, pb.ioVRefNum, ar.dir, ar.name);
- }
-
- ensure(fp->error || FileValid(fp));
-
- return(fp->error);
- END
- }
-
-